/*
 * car.h
 *
 *  Created on: 20/04/2011
 *      Author: Yotam and Gilad
 */

#ifndef CAR_H_
#define CAR_H_

#include <stdlib.h>
#include <stdbool.h>

typedef struct Car_t *Car;

typedef enum {
	CAR_NULL_ARGUMENT,
	CAR_OUT_OF_MEMORY,
	CAR_INVALID_PRICE,
	CAR_INVALID_KM,
	CAR_ALREADY_EXISTS,
	CAR_DOES_NOT_EXIST,
	CAR_IN_USE,
	CAR_NO_SALE,
	CAR_ALREADY_ON_SALE,
	CAR_SALE_PRICE_TOO_BIG,
	CAR_SUCCESS
} CarResult;

/**
 * carCreate: adds a new car.
 * @param licensePlate - the car's license plate.
 * @param name - the car's name.
 * @param price - the price of the car.
 * @param km - the Mileage car's current.
 * return:
 * a pointer to the new car.
 */
Car carCreate(int licensePlate,const char* name,int price, int km);

/**
 * carCopy: build a copy of the car.
 * @param carElement - the car to be copied.
 * return: a pointer to a copy of the car.
 */
void* carCopy(void* carElement);

/**
 * carCompareByName: compare between 2 cars by name.
 * @param carElement1 - the first car.
 * @param carElement2 - the second car.
 * return: 0 if equal, negative if car1 < car2 and positive otherwise
 */
int carCompareByName(void* carElement1, void* carElement2);

/**
 * carCompareByKm: compare between 2 cars by km.
 * @param carElement1 - the first car.
 * @param carElement2 - the second car.
 * return: 0 if equal, negative if car1 > car2 and positive otherwise
 */
int carCompareByKm(void* carElement1, void* carElement2);

/**
 * carCompareByLicensePlate: compare between 2 cars by license plate.
 * @param carElement1 - the first car.
 * @param carElement2 - the second car.
 * return: 0 if equal, negative if car1 < car2 and positive otherwise
 */
int carCompareByLicensePlate(void* carElement1, void* carElement2);

/**
 * carFilterNotInUse: checks the use status of a car. returns true if not in use
 *@param carElement - the car to check
 *return: true if not in use, false if in use.
 */
bool carFilterNotInUse(void* carElement);

/**
 * carFree: free the car.
 * @param carElement - element to be free.
 */
void carFree(void* carElement);

/**
 * carGetLicensePlate: gets the license plate of the car.
 * @param car - the car itself.
 * return: the license plate of the car.
 */
int carGetLicensePlate(Car car);

/**
 * carGetPrice: gets the price of the car.
 * @param car - the car itself.
 * return: the price of the car.
 */
int carGetPrice(Car car);

/**
 * carGetSalePrice: gets the sale price of the car.
 * @param car - the car itself.
 * return: the sale price of the car.
 */
int carGetSalePrice(Car car);

/**
 * carGetName: gets the name of the car.
 * @param car - the car itself.
 * return: the name of the car.
 */
char* carGetName(Car car);

/**
 * carGetKm: gets the car's km.
 * @param car - the car itself.
 * return: the km of the car.
 */
int carGetKm(Car car);

/**
 * carGetSaleKmMin: gets the car's minimum km.
 * @param car - the car itself.
 */
int carGetSaleKmMin(Car car);

/**
 * carGetSaleKmMax: gets the car's maximum km.
 * @param car - the car itself.
 */
int carGetSaleKmMax(Car car);

/**
 * carGetCarInUse: gets true if the car is in use, false otherwise.
 * @param car - the car itself.
 */
bool carGetCarInUse(Car car);

/**
 * carSale: sets a specific car rental sale.
 * @param car - the car itself.
 * @param kmMin - the minimum distance to travel there to enjoy
 * the promotional price.
 * @param kmMax - the maximum distance to travel there to enjoy
 * the promotional price.
 * @param salePrice - the discounted price of the car.
 * return:
 * CAR_INVALID_KM - The minimum distance for sale is less than one, or the
 * maximum distance for sale is smaller than the minimum.
 * CAR_INVALID_PRICE - if the price is zero or less.
 * CAR_IN_USE - if the car is currently at a client.
 * CAR_SALE_PRICE_TOO_BIG - Sale price does not pay.
 * CAR_SUCCESS - if the sale added successfully.
 */
CarResult carSale(Car car, int kmMin, int kmMax, int salePrice);

/**
 * carNoSale: removes a specific car rental sale
 * @param car - the car itself.
 * return:
 * CAR_IN_USE - if the car is currently at a client.
 * CAR_NO_SALE - if the car is not in a sale right now.
 * CAR_SUCCESS - the sale was removed successfully.
 */
CarResult carNoSale(Car car);

/**
 * carGetSaleStatus: checks whether there is sale or not
 * @param car - the car itself.
 * return: returns true if there is sale, false otherwise.
 */
bool carGetSaleStatus(Car car);

/**
 * carSetUseMode: this function sets the use mode of the car on or off
 * according to the boolean value sent to it.
 *@param car - the car to change its use mode
 *@param inUse - the use mode to be set
 * return:
 * 	CAR_NULL_ARGUMENT - if car is NULL
 * 	CAR_SUCCESS - otherwise
 */
CarResult carSetUseMode(Car car, bool inUse);

/**
 *	carUpdateKm: updates the kilometerage of the car by adding (or subtracting)
 *		the value held inside addedKm. The calling function should make sure
 *		the addedKm is valid. this function allow negative values.
 *@param car - the car to update its killometerage
 *@param addedKm - the km to added
 *return:
 *	CAR_NULL_ARGUMENT - if car is NULL
 *	CAR_SUCCESS - otherwise
 */
CarResult carUpdateKm(Car car, int addedKm);
#endif /* CAR_H_ */
